<?php

class LoginController extends Controller{
    
    function actionIndex(){
        $this->actionDo();
    }
    
    function actionDo(){
        $this->layout = '//layouts/column1';
        
        if(Yii::app()->user->isAuth()){
            $this->redirect(UserModule::url('profile/main'));
        }
        
        $scenario = 'insert';
        if($_SESSION['user']['login'] > USER_ATTEMPS2AUTHORIZE) $scenario='antiSpam';
        $_FORM = new FormLogin($scenario);
        
        if(!empty($_POST['FormLogin'])){
            $_SESSION['user']['login']++;
            $_FORM->attributes = $_POST['FormLogin'];
            if($_FORM->validate()){
                $_SESSION['user']['login'] = 0;
                if($_FORM->login()){
                    $this->refresh();
                }else{
                    Yii::app()->user->errorMessage($this, UserModule::t('message', 'Неверный логин\\пароль.'));
                }
            }
        }
        
        $this->render('form-login', array(
            '_FORM' => $_FORM
        ));
    }
    
}
